package cn.xiaopengstack.trigger.http;

import cn.xiaopengstack.domain.activity.service.armory.IActivityArmory;
import cn.xiaopengstack.domain.strategy.service.armory.IStrategyArmory;
import cn.xiaopengstack.trigger.api.IRaffleActivityService;
import cn.xiaopengstack.trigger.api.IRaffleArmoryService;
import cn.xiaopengstack.trigger.api.dto.ActivityDrawRequestDTO;
import cn.xiaopengstack.trigger.api.dto.ActivityDrawResponseDTO;
import cn.xiaopengstack.types.enums.ResponseCode;
import cn.xiaopengstack.types.model.Response;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author jiangyangang
 */
@Slf4j
@RestController
@RequestMapping("/api/${app.config.api-version}/raffle/armory")
//@CrossOrigin("${app.config.cross-origin}")
public class RaffleArmoryController implements IRaffleArmoryService {


    @Resource
    private IActivityArmory activityArmory;

    @Resource
    private IStrategyArmory strategyArmory;

    /**
     * 策略装配，将策略信息装配到缓存中
     * <a href="http://localhost:8091/api/v1/raffle/armory">/api/v1/raffle/armory/raffle_armory</a>
     *
     * @param activityId 策略ID
     * @return 装配结果
     */
    @RequestMapping(value = "raffle_armory", method = RequestMethod.POST)
    @Override
    public Response<Boolean> armory(@RequestParam Long activityId) {
        if (activityArmory.assembleActivitySkuByActivityId(activityId)
                && strategyArmory.assembleLotteryStrategyByActivityId(activityId)) {
            return Response.success(null);
        } else {
            return Response.error(null, ResponseCode.ACTIVITY_ARMORY_ERROR);
        }
    }

}
